local skel = fk.CreateSkill {
  name = "emo__xizhu",
}

skel:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#emo__xizhu",
  card_num = 2,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  card_filter = function (self, player, to_select, selected)
    return #selected < 2 and (#selected == 0 or Fk:getCardById(to_select).color ~= Fk:getCardById(selected[1]).color)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:recastCard(effect.cards, player, skel.name)
    if player.dead then return end
    room:addPlayerMark(player, "@@emo__xizhu-phase")
  end,
})

skel:addEffect(fk.TargetSpecified, {
  is_delay_effect = true,
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return target == player and not data.to.dead and (data.extra_data or {}).emo__xizhu_check
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = data.to
    if #to:getCardIds("he") > 1 then
      local _ , dat = room:askToUseActiveSkill(to, {
        skill_name = skel.name, cancelable = true, skip = true, prompt = "#emo__xizhu-recast", extra_data = { fix_prompt = "#emo__xizhu-recast" }
      })
      if dat then
        room:recastCard(dat.cards, to, skel.name)
        return false
      end
    end
    room:doIndicate(player, {to})
    room:damage { from = player, to = to, damage = 1, skillName = skel.name }
  end,
})

skel:addEffect(fk.CardUsing, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@@emo__xizhu-phase") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@emo__xizhu-phase", 0)
    data.extra_data = data.extra_data or {}
    data.extra_data.emo__xizhu_check = true
  end,
})


Fk:loadTranslationTable{
  ["emo__xizhu"] = "戏珠",
  [":emo__xizhu"] = "出牌阶段限一次，你可以重铸两张异色的牌，若如此做，你本阶段下一张牌指定目标后，其须重铸两张异色牌，否则你对其造成1点伤害。",

  ["@@emo__xizhu-phase"] = "戏珠",
  ["#emo__xizhu"] = "戏珠：重铸两张异色的牌",
  ["#emo__xizhu-recast"] = "戏珠：你须重铸两张异色的牌，否则受到1点伤害",
}

return skel
